<?php
/**
 * Date functions class file.
 *
 * @Autor Filipe Ritter Cruz
 * @Licença MIT
 * @Versão 1.0 $Data: 05-29-2011
 */
class DateHelper extends AppHelper
{

    function diffDate($d1, $d2, $type='', $sep='-')
    {
        $d1 = explode($sep, $d1);
        $d2 = explode($sep, $d2);
        switch ($type) {
            case 'A':
                $X = 31536000;
                break;
            case 'M':
                $X = 2592000;
                break;
            case 'D':
                $X = 86400;
                break;
            case 'H':
                $X = 3600;
                break;
            case 'MI':
                $X = 60;
                break;
            default:
                $X = 1;
        }
        $t1 = mktime(0, 0, 0, $d2[1], $d2[2], $d2[0]);
        $t2 = mktime(0, 0, 0, $d1[1], $d1[2], $d1[0]);
        return floor(($t1 - $t2) / $X);
    }

}

?>
